format PE64 CONSOLE
entry start

include 'include\win64a.inc'
include 'consts64.inc'

DEBUG equ 1
CODE_ALIGN equ 16

section '.text' code readable executable
start:

	sub	rsp, 0x28

	call	Performance_Init
	call	BitBoard_Init
	call	MoveMatrix_Init

;call DumpBitBoard
;call  DumpMatrixCell

	call	XBoard_Start
	xor	rcx, rcx
	call	[ExitProcess]

	ret

DumpBitBoard:
       xor	rax,rax
       mov	rcx, CellName_H8
       call	BitBoard_AddWhitePawn
       call	Console_DumpBitBoard
       ret

DumpMatrixCell:
	push	r9 r10
	mov	rcx, CellName_B4
	mov	rdx, PieceType_BlackPawn
	call	MoveMatrix_GetDirectFirstMove
	test	r9, r9
	jz	.end

virtual at r9
  .move SpeculativeMove
end virtual
virtual at r10
  .move_bak SpeculativeMove
end virtual
.loop:
	bt	[.move.Flags], SpeculativeMoveFlags_ValidBit
	jnc	.end

	call	Console_DumpMoveSimple

	mov	r10, r9

	mov	al, ' '
	call	Console_WriteChar

	mov	r9, [.move_bak.NextMove]
	test	r9, r9
	je     .no_next_move
	call	Console_DumpMoveSimple
	jmp	.next_move_ok
.no_next_move:
	mov	al, '-'
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
.next_move_ok:

	mov	al, ' '
	call	Console_WriteChar

	mov	r9, [.move_bak.NextGroupMove]
	test	r9, r9
	je     .no_next_group
	call	Console_DumpMoveSimple
	jmp	.next_move_group_ok
.no_next_group:
	mov	al, '-'
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
	call	Console_WriteChar
.next_move_group_ok:

	call	Console_WriteLine

	mov	r9, r10

	add	r9, SpeculativeMove_Size
	jmp	.loop
.end:
	pop	r10 r9
	ret

	;section '.edata' export data readable
;
;  export 'ChessEngine64.DLL',\
;	  Utils_UnwindBits,'UnwindBits',\
;	  GetMyCells,'GetMyCells'

include 'consts.inc'
include 'console/console-win64.inc'
include 'console/console.inc'
include 'utils\bfen64.inc'
include 'utils\fen.inc'
include 'utils\strings.inc'
include 'utils\performance.inc'

include 'ChessBoard64.inc'
include 'moves\moves.inc'
include 'moves\MoveMatrix64.inc'
include 'api/xboard.inc'


section '.data' data readable writeable
apiData ChessEngineApiData
Performance_Frequency_Value rq 1
rollback RollbackData
include 'strings.inc'
include 'board\bitboard-data.inc'

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL'

  import kernel,\
	 ExitProcess,'ExitProcess', \
	 GetStdHandle, 'GetStdHandle', \
	 WriteFile, 'WriteFile', \
	 ReadFile, 'ReadFile', \
	 GetSystemTimeAsFileTime, 'GetSystemTimeAsFileTime', \
	 QueryPerformanceCounter, 'QueryPerformanceCounter',\
	 QueryPerformanceFrequency, 'QueryPerformanceFrequency'


;section '.reloc' fixups data discardable